package cn.lunkr.sdkdemo.util;

import android.content.Context;
import android.content.SharedPreferences;

import cn.lunkr.base.CApp;


/**
 * 仅仅作为测试使用
 */
public class SPUtil {

    private static final String PREFERENCE_NAME = "text_sp";

    private SharedPreferences mSharedPreferences;

    private static SPUtil instance;

    public static final String TOKEN = "token";
    public static final String URL = "url";
    public static final String LOGIN_TYPE = "login_type";

    private SPUtil() {
        mSharedPreferences = CApp.get()
                .getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
    }

    public static SPUtil getInstance() {
        if (instance == null) {
            synchronized (SPUtil.class) {
                if (instance == null) {
                    instance = new SPUtil();
                }
            }
        }
        return instance;
    }

    public void saveString(String key, String value) {
        mSharedPreferences.edit().putString(key, value).commit();
    }

    /**
     * 获取字符串
     * @param key
     * @param defValue
     * @return bool
     */
    public String getString(String key, String defValue) {
        return mSharedPreferences.getString(key, defValue);
    }
}
